#!/bin/bash

baseDirForScriptSelf=$(cd "$(dirname "$0")"; pwd)
PWDNOW=${baseDirForScriptSelf}

eval $(grep logPath ${PWDNOW}/taginfo1.cfg) #
eval $(grep JOB_CON ${PWDNOW}/taginfo1.cfg) #
eval $(grep PROS_OTH ${PWDNOW}/taginfo1.cfg) #
eval $(grep PROS_4G ${PWDNOW}/taginfo1.cfg) #
eval $(grep TABLE_PATH ${PWDNOW}/taginfo1.cfg) #


DAY=$1
COUNT=0
echo "${DAY} task start at `date "+%Y-%m-%d %H:%M:%S"`"

logTagInfo=$logPath/taginfo/${DAY}
>${logTagInfo}/hive_pro

PROS_OTH=$PROS_OTH
PROS_4G=$PROS_4G

len=${#PROS_OTH[@]}


while [ $COUNT -lt $len ]
do
con_pro=`cat ${logTagInfo}/hive_pro | wc -l`
con=`ps -ef | grep taginfo_cache3 | grep ${DAY} | wc -l`
con=`expr $con + 0`


 if [[ "$con" -le "$JOB_CON" ]];then
    echo ${PROS_4G[$COUNT]} >> ${logTagInfo}/hive_pro
    nohup sh ${PWDNOW}/taginfo_cache3.sh ${DAY} ${PROS_OTH[$con_pro]} ${PROS_4G[$con_pro]} & COUNT=`expr $COUNT + 1`
	echo "$COUNT task started, params: ${DAY} ${PROS_OTH[$con_pro]} ${PROS_4G[$con_pro]}"
 fi
sleep 10

done

while [ 1 -eq 1 ]
do
con=`ps -ef | grep taginfo_cache3 |grep ${DAY} | wc -l`
if [ "$con" -eq "0" ];then
	echo "ALL DONE ! " >> ${logTagInfo}/hive_pro
	echo "${DAY} ALL DONE at `date "+%Y-%m-%d %H:%M:%S"`"
	exit 0
fi
sleep 30
done
